package com.seal.yoyoshop.web;

import com.seal.yoyoshop.bin.Goods;
import com.seal.yoyoshop.bin.Type;
import com.seal.yoyoshop.service.GoodsService;
import com.seal.yoyoshop.service.TypeService;
import com.seal.yoyoshop.service.impl.GoodsServiceImpl;
import com.seal.yoyoshop.service.impl.TypeServiceImpl;
import com.seal.yoyoshop.util.DBUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.awt.image.DataBuffer;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "IndexServlet", value = "/index/index")
public class IndexServlet extends HttpServlet {

    private GoodsService goodsService = new GoodsServiceImpl();
    private TypeService typeService = new TypeServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.getWriter().append("123321");
//        请求转发之前，先准备页面需要的数据

        request.setAttribute("flag",1);

        List<Type> typeList = typeService.getTypeList();
        request.setAttribute("typeList",typeList);

        List<Goods> goodsList = goodsService.getGoodsListByHotType(1);
        request.setAttribute("top1List",goodsList);

        List<Goods> goodsList2 = goodsService.getGoodsListByHotType(2);
        request.setAttribute("top2List",goodsList2);

        List<Goods> goodsList3 = goodsService.getGoodsListByHotType(3);
        request.setAttribute("top3List",goodsList3);

//        请求转发
        request.getRequestDispatcher("/index/index.jsp").forward(request, response);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
